//
//  BaseController.swift
//  weibo-mxm
//
//  Created by 马晓敏 on 16/1/11.
//  Copyright © 2016年 马晓敏. All rights reserved.
//

import UIKit
//oc中没有多继承,用协议替代
//没有实现必选的实现方法,直接报错


class BaseController: UITableViewController,VistorLoginViewDelegate {
//定义用户是否登录的标示
    var userLogin = UserAccountViewModel().userLogin
    //访客视图
    var visitorLoginView:VistorLoginView?
    
 //loadview为手写代码准备 ,一旦实现 sb/xib就会实现
 //在super.loadView之前,view没有被创建出来 追尊的话会造成igui
    
    //准备视图层次结构  在uiviewcontroller中将view准备出来
    override func loadView() {
//        super.loadView()
//        print(view)
        
     //自定义view
        
        if userLogin{
        super.loadView()
        
        }else {
            //自定义访客视图
            visitorLoginView = VistorLoginView()
//            v.backgroundColor = UIColor.redColor()
           
        //设置代理  
           visitorLoginView?.vistorViewDelegate = self
            
            
            view = visitorLoginView
            //设置导航条的item
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
          self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
        }
        
   
    }
    
 //MARK 实现协议方法
    
    func userWillRegister() {
        print(__FUNCTION__)
        
    }
    
    func userWillLogin() {
        print(__FUNCTION__)
     let oauth = OAuthViewController()
        let nav  = UINavigationController(rootViewController: oauth)
    //跳转到授权页面
     presentViewController(nav, animated: true, completion: nil)
        
    }
    
//会在viewwilllayoutsubviews方法中设置view的大大小
    override  func viewWillLayoutSubviews() {
    
     super.viewWillLayoutSubviews()
        print(view)
        print(view.classForCoder)
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

       
}
}